package com.young.eventcoach.coach;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.young.eventcoach.R;
import com.young.eventcoach.board.ImageManager;
import com.young.eventcoach.board.ImageRequest;
import com.young.eventcoach.main.TabFragment;
import com.young.eventcoach.network.NetworkRequest;
import com.young.eventcoach.network.NetworkRequest.OnDownloadCompletedListener;

public class EventCoachResultDetail extends TabFragment {
	ImageView iv_coach_result_detail;
	TextView tv_coach_result_detail_name;
	TextView tv_coach_result_detail_price;
	TextView tv_coach_result_detail_duration;
	TextView tv_coach_result_detail_level;
	TextView tv_coach_result_detail_tip;
	TextView tv_coach_result_detail_introduction;
	
	ImageRequest imageRequest;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.coach_result_detail, container,false);
		iv_coach_result_detail = (ImageView)view.findViewById(R.id.iv_coach_result_detail);
		tv_coach_result_detail_name = (TextView)view.findViewById(R.id.tv_coach_result_detail_name);
		tv_coach_result_detail_price = (TextView)view.findViewById(R.id.tv_coach_result_detail_price);
		tv_coach_result_detail_duration = (TextView)view.findViewById(R.id.tv_coach_result_detail_duration);
		tv_coach_result_detail_level = (TextView)view.findViewById(R.id.tv_coach_result_detail_level);
		tv_coach_result_detail_tip = (TextView)view.findViewById(R.id.tv_coach_result_detail_tip);
		tv_coach_result_detail_introduction = (TextView)view.findViewById(R.id.tv_coach_result_detail_introduction);
		
		tv_coach_result_detail_name.setText(getArguments().getString("name"));
		tv_coach_result_detail_price.setText(getArguments().getString("budget"));
		tv_coach_result_detail_duration.setText(getArguments().getString("duration"));
		tv_coach_result_detail_tip.setText(getArguments().getString("tip"));
		tv_coach_result_detail_introduction.setText(getArguments().getString("introduction"));
//		tv_coach_result_detail_level.setText(getArguments().getInt("level")+"");
		int level = getArguments().getInt("level");
		switch(level){
		case 1 :
			tv_coach_result_detail_level.setBackgroundResource(R.drawable.eventcoach_finalsub_star1);
			break;
		case 2 :
			tv_coach_result_detail_level.setBackgroundResource(R.drawable.eventcoach_finalsub_star2);
			break;
		case 3 :
			tv_coach_result_detail_level.setBackgroundResource(R.drawable.eventcoach_finalsub_star3);
			break;
		case 4 :
			tv_coach_result_detail_level.setBackgroundResource(R.drawable.eventcoach_finalsub_star4);
			break;
		case 5 :
			tv_coach_result_detail_level.setBackgroundResource(R.drawable.eventcoach_finalsub_star5);
			break;
			
		}
		
		
		
		String imageUrl = getArguments().getString("image");
		
		imageRequest = new ImageRequest(imageUrl);
		imageRequest.setOnDownloadCompletedListener(new OnDownloadCompletedListener() {
			@Override
			public void onDownloadCompleted(int result, NetworkRequest request) {
				if (result == NetworkRequest.PROCESS_SUCCESS) {
					if (imageRequest == request) {
						Bitmap bitmap = imageRequest.getBitmap();
						iv_coach_result_detail.setImageBitmap(bitmap);
						imageRequest = null;
					}
				}
			}
		});
		ImageManager.getInstance().enqueue(imageRequest);
		
		return view;
	}
}
